1. Field of the Invention
The present invention relates to an electronic control unit, which executes on-board rewriting of control programs and control data used for regulating operations of predetermined mechanisms or objects to be controlled. More particularly, the invention pertains to an apparatus and a method by which a rewrite count of control programs and control data stored in a nonvolatile memory is stored into a specific storage region of the nonvolatile memory.
2. Description of Related Art
In a conventional electronic control unit which is in practical use for controlling such objects as an engine and transmission of an automobile, there is provided a nonvolatile read-only memory that is electrically erasable and rewritable, such as a flash memory or EEPROM (hereinafter also referred to as an electrically rewritable ROM). The electrically rewritable ROM is so designed that control programs and control data stored therein can be rewritten in after the production of the electronic control unit.
In normal operation, this kind of electronic control unit controls an engine and other control objects according to control programs and control data stored in the electrically rewritable ROM thereof. When an external memory rewriting device is connected to the electronic control unit and a rewrite command is issued, the electronic control unit recognizes that a rewrite condition is met. Then, the electronic control unit performs transition to a rewrite mode, and in the rewrite mode, the contents of the electrically rewritable ROM are replaced with new contents (program and/or data) received from the memory rewriting device.
In the electronic control unit having the above onboard rewritable memory, it is rather easy to cope with a possible requirement that an operation sequence (control sequence) is to be altered due to any cause after placement on the market.
However, in the flash memory or EEPROM employed as an electrically rewritable ROM in the electronic control unit, a limitation is imposed on the allowable maximum number of times the contents stored therein may be rewritten (i.e., an allowable maximum erase/rewrite count of the contents of the memory).
Therefore, in the above electronic control unit, a rewrite count of the contents stored in the electrically rewritable ROM (hereinafter also referred to as a rewrite count of the electrically rewritable ROM or just as a rewrite count) is retained in a count information storage region allocated in the electrically rewritable ROM so that the contents of the electrically rewritable ROM will not be rewritten repeatedly beyond an allowable maximum rewrite count guaranteed for the electrically rewritable ROM.
In this kind of electrically rewritable ROM, all the bits of memory data are "1s" under a data-unwritten condition, and information can be added just by changing each bit data from "1" to "0" without having to perform an erase operation. On this ground, an approach has been proposed in which bit data is used to represent count information and each bit "0" is additionally written in the count information storage region of the electrically rewritable ROM.
However, this approach of additionally writing each bit "0" has a disadvantage that a rewrite count cannot be attained easily just by checking data in the count information storage region.
More specifically, in this conventional electronic control unit, there may occur that an automobile repair shop mechanic needs to know a current rewrite count of the electrically rewritable ROM when attempting to rewrite the contents stored in the electrically rewritable ROM. In this situation, using the memory rewriting device, the mechanic instructs the electronic control unit to send addresses and data of the count information storage region to the memory rewriting device. Thus, through the memory rewriting device, the mechanic produces a memory dump on a display monitor or paper so that each address and data received from the electronic control unit are presented in an associated fashion. By studying the memory dump, the mechanic can know the contents of the count information storage region in the electrically rewritable ROM. However, where this approach of additionally writing each bit "0" is employed, it is not easy to check the current rewrite count of the electrically rewritable ROM using the memory dump thus attained.
Further, in the flash memory, EEPROM or any similar electrically rewritable ROM, there is a possibility of "bit garbling" that any bit data is erroneously changed from "0" to "1" or vice versa on rare occasion.
Where each bit "0" is additionally written in each rewriting processing, it becomes impossible to determine an accurate value of the current rewrite count of the electrically rewritable ROM if any one of garbled bit patterns (1) to (4) described below occurs in the vicinity of a boundary between a bit string having "0s" already written and a bit string in which "0s" are not yet written (i.e., a bit string having "1s" intact) as exemplified in FIG. 9.
Garbled Bit Pattern (1)
With respect to the boundary between bit "bn" belonging to the bit string having "0s" already written and bit "bn+1" belonging to the bit string in which "0s" are not yet written, bit "bn" that must have "0" already written is garbled to "1". In this case, the current rewrite count of the electrically rewritable ROM is erroneously determined to be smaller than an actual correct count by one increment.
Garbled Bit Pattern (2)
With respect to the boundary between bits "bn" and "bn+1", bit "bn+1" that must not yet have "0" written is garbled to "0". In this case, the current rewrite count of the electrically rewritable ROM is mis executedly determined to be larger than an actual correct count by one increment.
Garbled Bit Pattern (3)
With respect to the boundary between bits "bn" and "bn+1", bit "bn-1" (immediately subsequent to bit "bn") that must have "0" already written is garbled to "1". In this case, an accurate rewrite count cannot be known since which one of bits "bn" and "bn-1" is garbled cannot be determined.
Garbled Bit Pattern (4)
With respect to the boundary between bits "bn" and "bn+1", bit "n+2" (immediately preceding bit "n+1") that must not yet have "0" written is garbled to "0". In this case, an accurate rewrite count cannot be known since which one of bits "bn+2" and "bn+1" is garbled cannot be determined.
Therefore, where th e above approach of additionally writing each bit "0" is employed in each rewriting processing, the mechanic may not attain an accurate value of the current rewrite count of the electrically rewritable ROM by checking the memory dump. Further, an accurate value of the current rewrite count cannot be attained in case the electronic control unit is so designed that it reads out data from the count information storage region of the electrically rewritable ROM before the start of rewriting processing and then forms a determination to indicate whether or not the current rewrite count of the electrically rewritable ROM has reached an allowable maximum rewrite count guaranteed for the electrically rewritable ROM.